let logger = require("pomelo-logger").getLogger(__filename);

module.exports = function (app) {
    return new Handler(app);
};

let Handler = function (app) {
    this.app = app;
};

Handler.prototype.findGameIdByCode = function (msg, session, callback) {
    let code = msg.code;
    if (!code) {
        callback(null, {
            resultCode: 404,
            message: "invalid code"
        });
        return;
    }
    let gameService = this.app.get("gameService");
    let gid = gameService.getGidByCode(code);
    logger.info('加入房间： ' + gid);
    if (gid > 0) {
        callback(null, {
            resultCode: 0,
            message: "ok",
            gid: gid
        });
    } else {
        callback(null, {
            resultCode: 404,
            message: "找不到对应的游戏"
        });
    }
};